﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ThienLoc.Admin
{
    public partial class QuanTriGioiThieu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadThongTinGioiThieu();
            }
            
        }

        protected void LoadThongTinGioiThieu()
        {
            string sql = "SELECT * FROM dbo.tblGioiThieu";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            txtGioiThieu.Value = dt.Rows[0]["NoiDung"].ToString();
        }

        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            string sql = "UPDATE dbo.tblGioiThieu SET NoiDung = @NoiDung,UserID = @UserID,UpdateDate = GETDATE()";
            List<SqlParameter> arrParams = new List<SqlParameter>();
            arrParams.Add(SqlHelper.CreateParameterObject("@NoiDung", SqlDbType.NVarChar, ParameterDirection.Input, txtGioiThieu.Value));
            arrParams.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.NVarChar, ParameterDirection.Input, Session["UserID"]));
            SqlHelper.ExecuteNonQuery(CommandType.Text, sql, arrParams);
            LoadThongTinGioiThieu();
        }
    }
}
